<?php
/**
*
* @author Username (Joe Smith) joesmith@example.org
* @package umil
* @copyright (c) 2008 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

/**
* @ignore
*/
define('UMIL_AUTO', true);
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);

$user->session_begin();
$auth->acl($user->data);
$user->setup();

if (!file_exists($phpbb_root_path . 'umil/umil_auto.' . $phpEx))
{
	trigger_error('Please download the latest UMIL (Unified MOD Install Library) from: <a href="http://www.phpbb.com/mods/umil/">phpBB.com/mods/umil</a>', E_USER_ERROR);
}

// The name of the mod to be displayed during installation.
$mod_name = 'POST_BOT';

/*
* The name of the config variable which will hold the currently installed version
* You do not need to set this yourself, UMIL will handle setting and updating the version itself.
*/
$version_config_name = 'post_bot_version';

$lang_array = array(
	'mods/info_acp_post_bot',
	'mods/post_bot',
);

$language_file = $lang_array;

/*
* Options to display to the user (this is purely optional, if you do not need the options you do not have to set up this variable at all)
* Uses the acp_board style of outputting information, with some extras (such as the 'default' and 'select_user' options)
*/
$options = array();

$all_available_extensions = pb::available_extensions();
foreach ($all_available_extensions as $value)
{	
	$extension 	= strtoupper($value[0]);
	$default 	= (pb::check_extension_status($value[0])) ? true : false;
	$options[$value[0]]	= array('lang' => $extension, 'type' => 'radio:yes_no', 'default' => $default, 'explain' => true);
}

$versions = array(
	'0.1.0' => array(
		'table_add' => array(
			array('phpbb_post_bot', array(
					'COLUMNS'		=> array(
						'post_bot_config'	=> array('VCHAR', ''),
						'post_bot_value'	=> array('MTEXT', ''),
					),
					'PRIMARY_KEY'	=> 'post_bot_config',
					'KEYS'			=> array(),
				),
			),
		),
		
		'config_add' => array(
			array('post_bot_installed', 1),
		),
	),
	
	'0.2.0'	=> array(
		'custom'	=> 'install_extensions',
	),
	
	'0.3.0' => array(
		// Alright, now lets add some modules to the ACP
		'module_add' => array(
			// First, lets add a new category
			array('acp', 'ACP_CAT_DOT_MODS', 'ACP_POST_BOT'),

			// Now we will add the settings and features modes.
			array('acp', 'ACP_POST_BOT', array(
					'module_basename'		=> 'post_bot',
				),
			),
		),
	),

);

// Include the UMIL Auto file and everything else will be handled automatically.
include($phpbb_root_path . 'umil/umil_auto.' . $phpEx);

function install_extensions($action, $version)
{
	global $umil;
	
	$pb_available_extensions = pb::available_extensions();
	foreach ($pb_available_extensions as $value)
	{	
		$extension_value = request_var($value[0], 1);	
		if ($action == 'install' || $action == 'update')
		{
			$umil->config_add($value[0], $extension_value);
			if ($extension_value == 1)
			{
				pb::install_post_bot_extension($value[0]);
			}
		}
		else
		{
			$umil->config_remove($value[0]);
		}		
	}
		
}

?>